package com.york.security.security;

import com.york.utils.exception.result.R;
import com.york.utils.util.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:未授权统一处理类
 * @Data: 2022/3/22 16:04
 * @Author: yangboxiong
 * @Version
 * @since JDK 1.8
 */
//身份验证入口
public class UnauthEntryPoint implements AuthenticationEntryPoint {

    /**
     * 在未授权时执行此方法
     *
     * @param httpServletRequest
     * @param httpServletResponse
     * @param e
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                         AuthenticationException e) throws IOException, ServletException {
        ResponseUtil.out(httpServletResponse, R.error());
    }
}
